#include <Ape/EventModel/EventArgs.h>

namespace Ape {
	namespace EventModel {
		EventArgs::EventArgs (Object* sender, int argsCount)
				: m_Sender (sender),
				m_Cancel (false),
				m_Args (argsCount, NULL),
				m_ArgsAutoDeletion (argsCount, false)
		{}
		EventArgs::~EventArgs() {
			foreach (i, Ape::Collections::Array<bool>, m_ArgsAutoDeletion) {
				if ( (bool) i) {
					del (m_Args[i.get_Position() ]);
				}
			}
		}
		
		void EventArgs::Cancel() {
			m_Cancel = true;
		}
		bool EventArgs::Cancelled() const {
			return m_Cancel;
		}
		
		/*
		Ape::Collections::Array<Object*>& EventArgs::Args() {
			return m_Args;
		}
		*/
		
		Object* EventArgs::get_Sender() const {
			return m_Sender;
		}
		
		void EventArgs::setArg (size_t iPos, Object* oVal, bool bAutoDelete) {
			if (m_ArgsAutoDeletion[iPos]) {
				del (m_Args[iPos]);
			}
			m_Args[iPos] = oVal;
			m_ArgsAutoDeletion[iPos] = bAutoDelete;
		}
		
		size_t EventArgs::get_ArgsCount() const {
			return m_Args.get_Size();
		}
	}
}
